package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.AnnounceDao;
import dao.UserDao;
import dao.impl.AnnounceDaoImpl;
import dao.impl.UserDaoImpl;
import model.Announces;

/**
 * Servlet implementation class HostServlet
 */
@WebServlet("/HostServlet")
public class HostServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HostServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setCharacterEncoding("utf-8");
		String userid = request.getParameter("userId");
		UserDao ud = new UserDaoImpl();
		AnnounceDao ad = new AnnounceDaoImpl();		
		try {
			request.setAttribute("user", ud.getUserById(userid));
			//得到主体信息
			List<Announces> AnnList = ad.queryAnnListByUserID(userid);
			System.out.println(AnnList.get(0).getAnnBody());
			request.setAttribute("AnnList",AnnList);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("pages/host.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
